
import java.util.Date;
import java.util.Observable;
import java.util.Timer;
import java.util.TimerTask;


//import java.util.Timer;

/**
 *
 * @author mortisjust
 */
public class Valve_1 extends Observable{
    private int preasure, level;
    private String state;
    private boolean b = false;
    Timer timer;
    
    public Valve_1(int sec){
        preasure = 0;
        level = 0;
        timer = new Timer();
        timer.scheduleAtFixedRate(timerTask, 0, 1000*sec);
    }

   public void setPreasure(int p){
    preasure = p;
   }
   public void setLevel(int l){
    level = l;
   }

   public void stopTimer(){
    timer.cancel();
   }

   public void setBoolean(){
    this.b = true;
   }

   public int getLevel(){ return level;}

//Timer Task--------------------------------------------------------------------
    TimerTask timerTask = new TimerTask()
     {
         /**
          * Método al que Timer llamará cada segundo. Se encarga de avisar
          * a los observadores de este modelo.
          */
        
         public void run()
         {
             setChanged();
             notifyObservers(new Date());
             level++;
             System.out.println("level: "+level);
         }
     };

}
